/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import shoppinglistprediction.*;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import MatlabRuntimeInterface.Engine;

/**
 *
 * @author Anon
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //Put your own damn direct path!!!!!
        String path = "./shoppinglistprediction/";

//  	Engine engine = new MatlabRuntimeInterface.Engine();
//  	try {
//              engine.open();
//              engine.getOutputString(500);

//              engine.evalString("test_inlasn();");
//              engine.getOutputString(500);

//              engine.close();

//  	}
//  	catch (Exception e) {
//  	    e.printStackTrace();
//  	}

 	FileInputStream file_in = null;
         StringTokenizer st;
         Vector<Double> inData = new Vector<Double>();
         AprioriCalculation apConsume = new AprioriCalculation(path,"data/config.txt","data/consume.csv","out/aprioripred.txt",5);

         try {
             file_in = new FileInputStream(path+"prediction.dat");
             BufferedReader data_in = new BufferedReader(new InputStreamReader(file_in));
             st = new StringTokenizer(data_in.readLine(), " ");
             inData = apConsume.stringTokanizer2Vector(st);

         } catch (FileNotFoundException ex) {
             System.out.println(ex.toString());
         } catch (IOException ex) {
             System.out.println(ex.toString());
         } finally {
             try {
                 file_in.close();
             } catch (IOException ex) {
                 Logger.getLogger(AprioriCalculation.class.getName()).log(Level.SEVERE, null, ex);
             }
         }

         System.out.println(inData);

         apConsume.aprioriProcess();

         TreeMap<Integer,Double> rules = apConsume.findeRules(inData);

         //Chec what works best

         for(int index : rules.keySet()){
             inData.set(index, inData.get(index)+rules.get(index));//just adds to the previous predicted value
         }
         System.out.println(inData);
        
    }
}
